#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2020/10/31 21:35
# @Author  : LJ
# @Site    : 
# @File    : 第二周_第三节.py
# @Software: PyCharm

''' 基本数据结构CRUD操作'''

# List 列表
# 增加
l = [1,2]
l1 = l + [3,4]
l2 = l * 10
l3 = l.append(5)
l4 = l.insert(0, 0)
print(l)
print(l1)
print(l2)
print(l3)
print(l4)
print(f'l : {id(l)},l1 : {id(l1)}, l2 : {id(l2)},l3 : {id(l3)},l4 : {id(l4)}')
print("=================================================")
# 检索
print(l)
print(l[0])
print(l[:])
print(l[2:])
print(l[:3])
print(l[-1:])
print(l[:-1])
print(l[::2])
print(l.index(0))
print(len(l))
print("==============================")
# 更新
l[1:] = [3]
print(l)
print(f'l : {id(l)}')
# 删除
l.remove(3)
print(l)
print(f'l :{id(l)}')
print(l.pop(0))
# 统计和排序
print(l.count(0))
l = [1,4,6,8,3,2]
print(id(l))
l1 = l.reverse()
print(f'{l} : {l1}')
print(l)
print(f'l{id(l)},l1{id(l1)}')
print("=====")
l2 = list(reversed(l))
l3 = list(l.__reversed__())
print(l2,l3)
print(id(l2),id(l3))
l4 = l.sort()
print(l,id(l))
l5 = list(sorted(l))
print(l5,id(l5))
l.sort(reverse=True)
print(l, id(l))
print("=============================================")
# Tuple 元组
# 检索
t = (1,2,3,4,5)
t1 = t[:]
print(t1)
print(f't:{id(t)}, t1:{id(t1)}')
print("================================================")
# dict 字典
# 增加
d = {'a':1,'b':2}
d1 = d['c'] = 3
print(d,id(d),id(d1))
d3 = {'d':4}
d2 = d.update(d3)
print(d2,id(d2))
d4 = d.setdefault('e',5)
print(d,d4)
print(id(d),id(d4))
# 检索
print(d['a'])
d5 = d['a']
print(d5)
print(d.get('a'))
print(d.keys())
print(d.values())
print(d.items())
#删除
d.pop('a')
print(d)
d.popitem()
print(d)
d.clear()
print(d)
print("===============")
# Set 集合
#增加 更新
s = {1,2,3,4,5}
s1 = {1,6,7}
s.update(s1)
print(s)
s.add(9)
print(s)
s2 = {10,11}
s.union(s2)
print(s)
# 检索
print(1 in s)

# 删除
s.remove(9)
print(s)
s.discard(10)
print(s)
s.pop()
print(s)